package com.estar.assistsurvy.adapter;

import java.util.List;

import com.estar.assistsurvy.R;
import com.estar.assistsurvy.entity.EsChangeDetailInfo;
import com.estar.assistsurvy.utils.TimeUtils;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class BalanceListviewAdapter extends BaseAdapter {

	private List<EsChangeDetailInfo> esChangeDetailInfoList;
	private LayoutInflater inflater;
	private Context context;

	public BalanceListviewAdapter(List<EsChangeDetailInfo> esChangeDetailInfoList, Context context) {
		super();
		this.context=context;
		this.esChangeDetailInfoList = esChangeDetailInfoList;
		inflater=LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return esChangeDetailInfoList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return esChangeDetailInfoList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		viewHolder holder;
		if(convertView==null){
			convertView=inflater.inflate(R.layout.listview_balance, null);
			holder=new viewHolder();
			holder.money=(TextView) convertView.findViewById(R.id.money);
			holder.name=(TextView) convertView.findViewById(R.id.name);
			holder.time=(TextView) convertView.findViewById(R.id.time);
			convertView.setTag(holder);
		}else{
			holder=(viewHolder) convertView.getTag();
		}
		EsChangeDetailInfo changeDetail=esChangeDetailInfoList.get(position);
		
		switch (Integer.valueOf(changeDetail.getCostType())) {
		case 1:
			holder.name.setText("查勘费");
			holder.money.setTextColor(context.getResources().getColor(android.R.color.holo_green_dark));
			break;

		case 2:
			holder.name.setText("岗位津贴");
			holder.money.setTextColor(context.getResources().getColor(android.R.color.holo_green_dark));
			break;

		case 3:
			holder.name.setText("提现");
			holder.money.setTextColor(context.getResources().getColor(android.R.color.black));
			break;

		default:
			break;
		}

		holder.time.setText(TimeUtils.getStringDate(changeDetail.getCreateTime()));
		holder.money.setText(changeDetail.getAmount());
		return convertView;
	}

	private class viewHolder{
		private TextView name,time,money;
	}

}
